package artandco.dao;

import java.util.List;

import javax.persistence.EntityManagerFactory;

import artandco.entites.Client;

/**
 * ClientDAO.java
 * 
 * @version 1.0
 * @date 26 mai 2011
 */
public class ClientDAO extends GenericDaoImpl<Client, Integer> {

	/**
	 * Constructeur
	 * 
	 * @param emf
	 */
	public ClientDAO(EntityManagerFactory emf) {
		super(Client.class, emf);
	}

	/**
	 * getClient
	 * 
	 * @param id
	 * @return Client
	 */
	public Client getClient(Integer id) {
		return (Client) super.read(id);
	}

	/**
	 * saveClient
	 * 
	 * @param p
	 * @return Client
	 */
	public Client saveClient(Client p) {
		Integer id = (Integer) super.getEmf().createEntityManager().createQuery("Select Max(p.id) FROM Client p")
			.getResultList().get(0);
		p.setId(id + 1);
		super.create(p);
		return p;
	}

	/**
	 * updateClient
	 * 
	 * @param p
	 */
	public void updateClient(Client p) {
		super.update(p);
	}

	/**
	 * deleteClient
	 * 
	 * @param p
	 */
	public void deleteClient(Client p) {
		super.delete(p);
	}

	/**
	 * getAllClients
	 * 
	 * @return List<Marque>
	 */
	public List<Client> getAllClients() {
		return super.readAll();
	}

	/**
	 * getAllClientTries
	 * 
	 * @return List<Client>
	 */
	public List<Client> getAllClientTries() {
		String HQL = "select o from Client o order by Nom";
		return execute(HQL);
	}

}
